package edu.yuhf.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import edu.yuhf.dao.iface.UserDao;
import edu.yuhf.entity.User;

@Repository
public class UserHibernateDaoImpl implements UserDao {

	@Resource
	SessionFactory sessionFactory;
	
	public boolean checkNameAndPassword(String name, String password) {
		boolean flag=false;
		String hql="from User user where user.name=:name and user.password=:password";	//hql，hql操作的是对象
		Session session=sessionFactory.getCurrentSession();
		Query query=session.createQuery(hql);
		query.setString("name",name);
		query.setString("password", password);
		List<User> list=query.list();
		if(list.size()!=0){
			flag=true;
		}
		return flag;
	}

	@Override
	public User insertUser(User user) {
		Session session=sessionFactory.getCurrentSession();
		Long id=(Long) session.save(user);
		user.setId(id);
		return user;
	}

}
